﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using KPIS.GERP.GHRMS.BLL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.MODEL;
using KPIS.DBM; 

namespace KPIS.GERP.GHRMS.APP.App_UI.UserControls
{
    public partial class RC_Command : System.Web.UI.UserControl
    {


     
        private object _dataItem = null;

        protected void Page_Load(object sender, EventArgs e)
        {

          
            

        }



        protected bool IsUserControlPostBack
        {
            get
            {
                return this.ViewState["IsUserControlPostBack"] != null;
            }
        }

  
        protected override void OnLoad(System.EventArgs e)
        {
            base.OnLoad(e);
       
            if (!IsUserControlPostBack)
            {

                BindComboGroup(); 
                BindRadio();
                this.ViewState.Add("IsUserControlPostBack", true);

            }



            if (DataItem != null)
            {
                //   cbGender.ListGenderComboBox();

     
                if (!(DataItem is Telerik.Web.UI.GridInsertionObject))
                {
               //     BindRadio2();
               //     lblPenSeq.Text   = DataBinder.Eval(DataItem, "cr_seq").ToString();

               //     radStatus.SelectedValue = DataBinder.Eval(DataItem, "record_status").ToString();

               ////     txtName.Text = DataBinder.Eval(DataItem, "cr_name").ToString(); 
        
             
                }


             

                btnUpdate.Visible = !(DataItem is Telerik.Web.UI.GridInsertionObject);
                btnAddnew.Visible = (DataItem is Telerik.Web.UI.GridInsertionObject);
            }


       
      
        }


        private void BindRadio()
        {
            CrimesBLL obj = new CrimesBLL();
            DataTable dt;
            dt = obj.SelectStatus();

            if (dt != null && dt.Rows.Count > 0)
            {
             
                //foreach (DataRow cur in dt.Rows)
                //{
                //    ListItem Li = new ListItem();
                //    Li.Text = cur["record_status_name"].ToString();// + " " + ((DateTime)cur["act_start_date"]).ToString("dd/MM/yyyy", new CultureInfo("th-TH")) + " ถึง " + ((DateTime)cur["act_end_date"]).ToString("dd/MM/yyyy", new CultureInfo("th-TH"));
                //    Li.Value = cur["record_status"].ToString();
                //    radStatus.Items.Add(Li);
                //}

                //radStatus.DataBind();
                //radStatus.SelectedIndex = 1;
            }
            else
            {
              //  radStatus.Items.Clear();
            }




        }

        private void BindRadio2()
        {
            CrimesBLL obj = new CrimesBLL();
            DataTable dt;
            dt = obj.SelectStatus();

            if (dt != null && dt.Rows.Count > 0)
            {
                //radStatus.Items.Clear();
                //radStatus.DataSource = dt;
                //radStatus.DataTextField = "record_status_name";
                //radStatus.DataValueField = "record_status";
                //foreach (DataRow cur in dt.Rows)
                //{
                //    ListItem Li = new ListItem();
                //    Li.Text = cur["record_status_name"].ToString();// + " " + ((DateTime)cur["act_start_date"]).ToString("dd/MM/yyyy", new CultureInfo("th-TH")) + " ถึง " + ((DateTime)cur["act_end_date"]).ToString("dd/MM/yyyy", new CultureInfo("th-TH"));
                //    Li.Value = cur["record_status"].ToString();
                //    radStatus.Items.Add(Li);
                //}

              //  radStatus.DataBind();
      
            }
            else
            {
              //  radStatus.Items.Clear();
            }




        }



        public object DataItem
        {
            get
            {
                return this._dataItem;
            }
            set
            {
                this._dataItem = value;
            }
        }
        protected void btnAddnew_Click(object sender, EventArgs e)
        {

         
 
        }


        protected void btnUpdate_Click(object sender, EventArgs e)
        {

     



        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {

        }




        private IEmployeeBLL empBLL = new EmployeeBLL();

        protected void btnFindEmp_Click(object sender, ImageClickEventArgs e)
        {


            string st = Hide.Value;
            //if (!(DataItem is Telerik.Web.UI.GridInsertionObject))
            //    st = DataBinder.Eval(DataItem, "req_seq").ToString();
            EmployeeInfo infoEmp;
            IList<EmployeeInfo> infoList = empBLL.ListEmployees(st);
            infoEmp = infoList[0];


            // infoEmp.Class.Sequence != null

          lblEmpSeq.Text = infoEmp.Sequence.ToString();
           
        }





        private void BindComboGroup()
        {
            RC_CommandBLL obj = new RC_CommandBLL();
            DataTable dt;
            dt = obj.SelectComboGroup();



            ComboGroup.DataValueField = "cmd_group_seq";
            ComboGroup.DataTextField = "cmd_group_name";

            ComboGroup.DataSource = dt;
            ComboGroup.DataBind();

        }

        private void BindComboType(int group_seq)
        {
            RC_CommandBLL obj = new RC_CommandBLL();
            DataTable dt;
            dt = obj.SelectComboType(group_seq);



            ComboType.DataValueField = "cmd_type_seq";
            ComboType.DataTextField = "cmd_type_name";

            ComboType.DataSource = dt;
            ComboType.DataBind();

        }

       

        protected void ComboGroup_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
        {

            BindComboType(int.Parse(ComboGroup.SelectedValue));   

        }

        protected void Type_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
        {



        }

        protected void ComboGroup_TextChanged(object sender, EventArgs e)
        {

        }

        protected void Type_TextChanged(object sender, EventArgs e)
        {

        }

        protected void ComboType_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
        {

        }

        protected void ComboType_TextChanged(object sender, EventArgs e)
        {

        }


       
   

    }
}